#include "sysfunc.h"
#include <error.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>


SigFunc
signal(int signo, SigFunc func) {
	struct sigaction act, oldact;
	memset(&act, 0, sizeof(act));
	act.sa_handler = func;
	sigemptyset(&act.sa_mask);

	if (signo == SIGALRM) {
#ifdef SA_INTERRUPT
		act.sa_flags |= SA_INTERRUPT;
#endif
	} else {
#ifdef SA_RESTART
		act.sa_flags |= SA_RESTART;
#endif
	}

	if (sigaction(signo, &act, &oldact) != 0)
		return (void*)-1;
	return oldact.sa_handler;
}

SigFunc 
Signal(int signo, SigFunc func) {
	SigFunc ret = signal(signo, func);
	if ((int)(ssize_t)ret == -1)
		error_dump("fail to set signal");
	return ret;
}
